/*
* @Author: root
* @Date:   2017-12-06 23:23:05
* @Last Modified by:   root
* @Last Modified time: 2017-12-07 23:48:13
*/
'use strict';
require('./index.css');
require('page/common/nav/index.js');
require('page/common/header/index.js');
var navSide         = require('page/common/nav-side/index.js');
var _utils          = require('util/util.js');
var _order          = require('service/order-service.js');
var templateIndex   = require('./index.string');

var page = {
	data : {
		orderNumber : _utils.getUrlParam('orderNumber')
	},
	init : function(){
		this.onload();
		this.binEvent();
	},
	onload  : function(){
		//初始化左侧菜单
		navSide.init({
		name:'order-list'
		});
		//加载detail数据  
		this.loadDetail();
	},
	binEvent : function(){
		var _this = this;
		$(document).on('click','.order-cancel',function(){
			if(window.confirm("确实要取消该订单么")){
					_order.cancelOrder(_this.data.orderNumber,function(res){
					_utils.successTips("该订单取消成功");
					_this.loadDetail();
				},function(errMsg){
					_utils.errorTips(errMsg);
				});
			}
			
		})
	},
	//加载订单列表
	loadDetail : function(){
		var orderDetailHtml 	 = '',
					_this 	 = this,
					$content = $('.content');
					$content.html('<div class="loading"></div>');
				   _order.getOrderDetail(this.data.orderNumber,function(res){
					_this.dataFilter(res);
					orderDetailHtml = _utils.renderHtml(templateIndex,res);
					//渲染html
					$content.html(orderDetailHtml);
					
				},function(errMsg){
					$content.html('<p class="err-tip">'+errMsg+'</p>');
				});
	},//数据的适配
	dataFilter : function(data){
		data.needPay 	  = data.status == 10;
		data.isCancelable = data.status == 10;

	}
	
};
$(function(){
	page.init();
});